
//+------------------------------------------------------------------+
//|                                                         Demo.mq4 |
//|                                                       Codersguru |
//|                                         http://www.forex-tsd.com |
//+------------------------------------------------------------------+
#property copyright "Various sources"
#property link      

#import "speak_b6.dll"
	bool gSpeak(string text, int rate, int volume);
#import 
//external input for sounds
extern bool 			useTTS = true;       	//for text-to-speech
extern bool 		soundAlert = false;  		// alternative bells and whistles for .wav output
extern string 		signal_buy = "ding_up.wav";
extern string 		signal_sell= "ding_dn.wav";

//-- use these as triggers to shut up the audio after one sound output.
bool SoundBuy  = true;
bool SoundSell = true;
bool SoundArrDn = true; 
bool SoundArrUp = true;
//-- other variables for the code below
int  iPeriod;
string  sSymbol, sAudio;

int init() {

    
   
   if(useTTS) {	  // If you use TTS in this instance, some variables will initialize here
   iPeriod=Period();
   sSymbol=Symbol();
   AudioString();
   }

	return(0);
  }
 
int start()
  {
   
  //... audio alert for variables or conditions (values of signal from your indicator e.g. 1 = buy, -1 = sell, 0 = do nothing or Analyze Exit
   if(gv==1) {
               if(SoundBuy && useTTS) gSpeak(sAudio+", Analyze Buy",1,100);
                  else if(SoundBuy && soundAlert) PlaySound (signal_buy);        
            SoundBuy = false; SoundSell = true;
            } 
  if(gv==-1) {
               if(SoundSell && useTTS) gSpeak(sAudio+", Analyze Sell",1,100);
                  else if(SoundSell && soundAlert) PlaySound (signal_sell);        
            SoundSell = false; SoundBuy = true;
            } 
   
   return(0);
  }
//+------------------------------------------------------------------+
//+ Function called in init() to create string for audio "Symbol + TimeFrame" from Symbols_.csv in MQL4/Files
//+ Maintain in csv file: "Symbol as provided by the broker" , "Spoken text for this symbol", e.g.
//+      AUDUSD,Aussie
//+      EURUSD,Euro
//+		etc...
//+------------------------------------------------------------------+
void AudioString () {
    string sSymbols[][2];
    string sMsg;
    int x,i;
    
    x=StringArrayLoad("Symbols_.csv", sSymbols, 2);
    if(x<1) sMsg=StringConcatenate(sMsg,"Error "+GetLastError()+" reading file Symbols_.csv\n");  
    for(i=0; i<x; i++) {
      if(sSymbols[i][0]==sSymbol) break;
    }
    if(i<x) sAudio=sSymbols[i][1];
    else    {sMsg=StringConcatenate(sMsg,"Symbol not found\n");
             Alert(sMsg);
             }
    string sPeriods[9][2]={   //may need to add a line for non-stadard timeframes, as well as changle sPeriods[9][2] to sPeriods[10][2]
							  "1", "1 minute",
                              "5", "5 minutes",
                             "15", "15 minutes",
                             "30", "30 minutes",
                             "60", "1 hour",
                            "240", "4 hour",
                           "1440", "Daily",
                          "10080", "Weekly",
                          "43200", "Monthly"
						  
                         }; 
    for(i=0; i<9; i++)  {  //change i<9 to i< number of lines above as required
      if(sPeriods[i][0]==IntegerToString(iPeriod)) break;
    }
    if(i<9) {sAudio=StringConcatenate(sAudio," ",sPeriods[i][1]," ");
    //Print(sAudio);
    }
    else    {sMsg=StringConcatenate(sMsg,"Period not found\n");
             Alert(sMsg);
             }
  }

//+------------------------------------------------------------------+
//| StringArrayLoad()                                                |
//+------------------------------------------------------------------+
int StringArrayLoad(string sFile, string& A[][], int iColumns) 
  {
    int handle = FileOpen(sFile, FILE_CSV|FILE_READ, ";"), i, iStart, iPos;
//----
    if(handle < 1) 
      {
        Alert("File:", sFile, " error "+GetLastError());
        return(-1);
      }
    string sLine;
    int iRows = ArrayRange(A,0), iLinesRead = 0;
//----
    while(FileIsEnding(handle) == false) 
      {
        sLine = FileReadString(handle);
        iStart = StringLen(sLine);
        //----
        if(iStart < 1 || StringSubstr(sLine,0,2) == "//") 
            continue; // empty strings or comment lines dropped
        //----
        if(iLinesRead >= iRows) 
          {
            if(ArrayResize(A,iRows+1) == 0 ) 
              {
                Alert("StringArrayLoad() error ", GetLastError());
                return(-1);
              }
            iRows += 1;
          }
        //----
        if(StringFind(sLine, ",,", 0) >= 0 || StringSubstr(sLine, iStart - 1, 1) == ",") 
          {
            Alert("File:", sFile, " Line:", iLinesRead, " NULL value");
            break;
          }
        sLine = sLine + ",";
        iStart = 0;
        //----
        for(i = 0; i < iColumns; i++) 
          {
            iPos = StringFind(sLine, ",", iStart);
            A[iLinesRead][i] = StringSubstr(sLine, iStart, iPos - iStart);
            iStart = iPos + 1;
          }
        iLinesRead++;
      }
    FileClose(handle);
    return (iLinesRead);
  }



